<?php

use yii\helpers\Html;
use kartik\detail\DetailView;
use backend\models\Tags;
use backend\models\Country;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model backend\models\ProjectSingle */
/* @var $form yii\widgets\ActiveForm */

//省市
$modelCountry = new Country();
$arr_provinces = $modelCountry->getProvinces();
$arr_cities = [];
if ($model->province) {
    $province = implode('', $modelCountry->getProvinces("id =" . $model->province));
    $arr_cities = $modelCountry->getProvinces("pid = $model->province");
} else {
    $province = '';
}
if ($model->city) {
    $city = implode('', $modelCountry->getProvinces("id=" . $model->city));
} else {
    $city = '';
}

//标签    
$arr_tag = $model->tag;
$arr_tag_tag = [];
if ($model->tag && is_array($arr_tag) && count($arr_tag) > 0) {
    foreach ($arr_tag as $item) {
        $arr_tag_tag[] = Tags::findOne(['id' => $item])->title;
    }
    $tags = implode(',', $arr_tag_tag);
} else {
    $tags = '';
}
?>
<div class="container">
    <div class="project-single-form">

        <?php
        echo DetailView::widget([
            'model' => $model,
            'condensed' => true,
            'hover' => true,
            'mode' => 'edit',
            'panel' => [
                'heading' => '项目信息',
                'headingOptions' => ['template' => '{title}'],
                'type' => DetailView::TYPE_INFO,
                'footer' => ($model->owner == Yii::$app->user->id && $model->is_published == 0) ?
                    Html::a('<buttron class="btn btn-info"><span class="glyphicon glyphicon-share-alt"></span>发布到点金人</buttron>', 'javascript:void(0);', ['data-toggle' => 'modal', 'data-target' => '#publish']) : '',
                'footerOptions' => ['class' => 'pull-right', 'tag' => 'h4', 'template' => '{buttons}{title}']
            ],
            'formOptions' => ['options' => ['data-pjax' => true],],
            'hideIfEmpty' => false,//如果有空字段则隐藏
            'buttons1' => '{update}',
            'buttons2' => '{view} {reset} {save}',
            'updateOptions' => ['label' => '<span class="btn btn-info">编辑</span>'],
            'viewOptions' => ['label' => '<span class="btn btn-info">查看</span>'],
            'saveOptions' => ['label' => $model->id == '' ? '<span class="btn btn-info">保存</span>' : (($model->id && ($model->owner == Yii::$app->user->id || in_array(Yii::$app->user->identity->realname, Yii::$app->params['package_ease_personal']))) ? '<span class="btn btn-info">保存</span>' : '')],
            'resetOptions' => ['label' => '<span class="btn btn-info">重置</span>'],
            'attributes' => [
                'title',
                [
                    'attribute' => 'level',
                    'type' => DetailView::INPUT_RADIO_LIST,
                    'items' => Yii::$app->params['project_single_level_label'],
                    'value' => Yii::$app->params['project_single_level_label'][$model->level],
                    'valueColOptions' => ['class' => 'form-inline', 'style' => 'valign:center;']
                ],
                [
                    'attribute' => 'category',
                    'type' => 'radioList',
                    'items' => Yii::$app->params['project_single_category'],
                    'value' => Yii::$app->params['project_single_category'][$model->category],
                    'valueColOptions' => ['class' => 'form-inline'],
//                'label' => "<span class='text-danger'>" . $model->getAttributeLabel('category') . "*</span>"
                ],
                [
                    'columns' => [
                        [
                            'attribute' => 'province',
                            'type' => DetailView::INPUT_SELECT2,
                            'value' => $province,
                            'widgetOptions' => [
                                'data' => $arr_provinces,
                                'options' => ['placeholder' => '选择省份 ...'],
                                'pluginOptions' => [
                                    'allowClear' => true
                                ]
                            ],
//                        'label' => "<span class='text-danger'>" . $model->getAttributeLabel('province') . "*</span>",
                            'valueColOptions' => ['style' => 'width:30%']
                        ],
                        [
                            'attribute' => 'city',
                            'type' => DetailView::INPUT_DEPDROP,
                            'widgetOptions' => [
                                'type' => 2,
                                'data' => count($arr_cities) > 0 ? $arr_cities : [],
                                'pluginOptions' => [
                                    'depends' => ['projectsingle-province'],
                                    'placeholder' => '选择城市...',
                                    'url' => Url::to(['/country/get-project-single-city',]),
                                ]
                            ],
                            'value' => $city,
                        ],
                    ],
                ],
                [
                    'attribute' => 'tag',
                    'type' => DetailView::INPUT_SELECT2,
                    'widgetOptions' => [
                        'data' => Tags::getAllTags(),
                        'options' => ['placeholder' => '选择标签'],
                        'pluginOptions' => [
                            'allowClear' => true,
                            'multiple' => true,
                        ]
                    ],
                    'value' => $tags,
                ],
                [
                    'attribute' => 'tagTitle',
                    'label' => '自定义标签',
                    'options' => ['placeholder' => '住宅，土地等等，多个标签用逗号隔开']
                ],
                'creditor',
                [
                    'attribute' => 'detail',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'asset',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                'address',
                'area',
                [
                    'attribute' => 'history',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => ''],
                ],
                [
                    'columns' => [
                        [
                            'attribute' => 'price', 'valueColOptions' => ['style' => 'width:15%'], 'format' => 'decimal',
//                        'label' => "<span class='text-danger'>" . $model->getAttributeLabel('price') . "*</span>",
                        ],
                        'price_per_area:decimal', 'price_pre_evaluate',
                    ],
                ],
                [
                    'attribute' => 'evaluate_by',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'highlights',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => '推介理由'],
                ],
                [
                    'attribute' => 'contact',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'source',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => '项目信息来源'],
                ],
                [
                    'attribute' => 'follow',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => '过会备注'],
                ],//过会备注
            ]
        ]);
        ?>

    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="publish" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="publish2djr">发布到点金人</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <?php
                if (Yii::$app->controller->action->id == 'update') {
                    echo $this->render('_form_publish2djr', ['model' => $model, 'projectSingleDjrModel' => $projectSingleDjrModel, 'projectDjr' => $projectDjr, 'projectMappingDjr' => $projectMappingDjr, 'projectSingleAssetDjr' => $projectSingleAssetDjr, 'projectFileDjr' => $projectFileDjr,]);
                }
                ?>
            </div>

        </div>
    </div>
</div>